package page.sample.ClientPage;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import page.MyFirstWebPage;
import page.sample.AuthorizationPage;
import app.MyFirstWebApplication;
import dao.impl.ClientDao;
import entity.Client;
import entity.InfoUser;

public class EditProfilePage extends WebPage {

	public EditProfilePage(final InfoUser infoUser) {

		Form<InfoUser> form = new Form<InfoUser>("form",
				new CompoundPropertyModel<InfoUser>(infoUser));

		form.add(new TextField<String>("name"));
		form.add(new TextField<String>("surname"));

		final ClientDao clientDao = new ClientDao(
				MyFirstWebApplication.DATA_XML_FOLDER);

		form.add(new SubmitLink("save") {

			@Override
			public void onSubmit() {
				super.onSubmit();
				if (infoUser != null)
					clientDao.update(new Client(infoUser));
				setResponsePage(new AuthorizationPage());
			}

		});

		form.add(new Link("cancel") {

			@Override
			public void onClick() {
				setResponsePage(new MyFirstWebPage());
			}

		});

		add(new Link("ShowProfile") {

			@Override
			public void onClick() {
				setResponsePage(new ShowProfilePage(infoUser));

			}

		});

		add(new Link("EditProfile") {

			@Override
			public void onClick() {
				setResponsePage(new EditProfilePage(infoUser));

			}

		});

		add(new Link("exit") {

			@Override
			public void onClick() {
				setResponsePage(new AuthorizationPage());

			}

		});
		
		add(new Link("showCard")
		{

			@Override
			public void onClick() {
				setResponsePage(new ShowCreditCardPage(infoUser));
				
			}
			
		});

		add(form);
	}
}
